<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/index.css" />
		<script src="../../js/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/vant.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/ajax.js" type="text/javascript" charset="utf-8"></script>
		<script src="html5plus://ready"></script>
		<style type="text/css">
			#header {
				background-color: red;
				margin-bottom: 10px;
			}
			.van-nav-bar__title {
				color: white;
				font-size: 15px;
			}
			.van-nav-bar .van-icon {
				color: white;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<van-row>
				<van-nav-bar id="header" title="修改昵称"  left-arrow  @click-left="back"></van-nav-bar>
			</van-row>
			<van-row>
				<van-col span="24">
					<van-cell title="昵称" v-bind:value="name" />
				</van-col>
				<van-col span="24">
					<van-field v-model="newname" center clearable label="新昵称" placeholder="输入新昵称">
					</van-field>
				</van-col>
				<van-col span="16" offset="4">
					<van-button type="danger" style="width: 100%; margin-top: 30px;"  @click="updataName">完成</van-button>
				</van-col>
			</van-row>
		</div>
	</body>
	<script type="text/javascript">
		var app =new Vue({
			el:"#app",
			data:{
				name:"",
				newname:""
			},
			mounted:function(){
					var _this=this;
					_this.key=localStorage.getItem("keys");
					_this.name=localStorage.getItem("name");
					plus.key.addEventListener("backbutton",function(){  
						var wv = plus.webview.currentWebview();
						plus.webview.close(wv.id);
					});  
				},
			methods:{
				change:function(){
					plus.webview.create("up_Photo.html","up_Photo");
					plus.webview.show("up_Photo");
					plus.webview.close("personal _data");
				},
				updataName:function(){
					var _this=this;
					ajax({
						type:"post",
						url:"http://dsapi.ysd3g.com/API/ChangeNickName",
						dataType:"JSONP",
						data:{
							key:_this.key,
							nickName:_this.newname
						},	
						success:function(res){
							if(res.Error==true){
								app.$toast("修改失败");
							}
							else{
								console.log(res);
								app.$toast("修改成功");
								localStorage.setItem("name",_this.newname);	
								// console.log(res);
								plus.webview.getWebviewById("Person").reload(true);
								plus.webview.getWebviewById("personal _data").reload(true);
								_this.$toast("修改昵称成功")
								setTimeout(function(){
									var vm=plus.webview.currentWebview();
									plus.webview.close(vm.id);
								},1000);
							}	
						}
					});
				},
				back:function(){
					var vm =plus.webview.currentWebview();
					plus.webview.close(vm.id);
				}
			}
			
		})
	</script>
</html>
